package com.zlb.sms.controller;

import com.zlb.sms.pojo.*;
import com.zlb.sms.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
public class studentController {
    @Resource
    StudentService service;
    @PostMapping("Login")
    public int Login(Student student){
        int isLogin = service.Login(student);
        return isLogin;
    }
    //获取院校
    @GetMapping("/getCollegeInfo")
    public List<College> getCollegeInfo(){
        return service.getCollegeInfo();
    }
    //获取专业
    @GetMapping("/getMajorInfo")
    public List<Major> getMajorInfo(){
        return service.getMajorInfo();
    }
    //获取班级
    @GetMapping("/getClassInfo")
    public List<ClassName> getClassInfo(){
        return service.getClassInfo();
    }
    //添加学生
    @PostMapping("/addStudent")
    public int addStudent(Student student){
        SimpleDateFormat format = new SimpleDateFormat("y");
        String  date = format.format(new Date())+"-9-1"; //2024-9-1
        student.setEnrollmentDate(date);
        return service.addStudent(student);
    }
    //获取学生信息列表
    @GetMapping("/getStudentInfo")
    public List<StudentVo> getStudentInfo(){
        return service.getStudentInfo();
    }
    //通过id删除学生
    @PostMapping("/delStudentById")
    public int delStudentById(int id){
        return service.delStudentById(id);
    }
    //更新学生信息
    @PostMapping("/updateStudent")
    public int updateStudent(Student student){
        return service.updateStudent(student);
    }
}
